<template>
  <el-dialog
    width="80%"
    @open="handleOpen"
    @close="handleClose"
    title="详情"
    :visible="dialogVisible"
  >
    <el-form :model="detailData" label-width="120px" label-position="left">
      <h1>房屋信息</h1>
      <el-row>
        <el-col :span="8">
          <el-form-item label="房屋名">
            {{ detailData.name }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="房屋地址">
            {{ detailData.address }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="所在地区">
            {{ detailData.area.name }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="房东名">
            {{ detailData.user.nickName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="创建时间">
            {{ detailData.createdAt | timeFilter }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="房屋状态">
            {{
              detailData.status == 1
                ? "下架"
                : detailData.status == 2
                ? "上架"
                : detailData.status == 3
                ? "已出租"
                : "暂存"
            }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="租金">
            {{ detailData.rent }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否是学区房">
            {{ detailData.isSchool ? "是" : "否" }}
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="detailData.isSchool">
          <el-form-item label="所在学区">
            {{ detailData.schoolName }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="相关描述">
            {{ detailData.description }}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="相关图片">
            <el-image
              v-for="item in detailData.imgs.split(',')"
              :key="item"
              style="width: 100px; height: 100px"
              :src="item"
            ></el-image>
          </el-form-item>
        </el-col>
      </el-row>
      <h1 v-if="userInfo">租客信息</h1>
      <el-row v-if="userInfo">
        <el-col :span="8">
          <el-form-item label="租客头像">
            <el-image
              style="width: 80px;height: 80px"
              :src="userInfo.picture || require('@/common/img/null.jpg')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="租客昵称">
            {{ detailData.askUser.nickName }}
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="租客姓名">
            {{ userInfo.firstName + userInfo.lastName || "未知" }}
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button @click="handleClose">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import detailDialog from "../../../mixins/detailDialog";

export default {
  name: "detailDialog",
  mixins: [detailDialog],
  data() {
    return {
      detailData: {
        name: "",
        address: "",
        area: {},
        user: {},
        rent: "",
        createdAt: "",
        status: "",
        isSchool: "",
        schoolName: "",
        imgs: "",
        description: "",
        askUser: {}
      },
      getDetailUrl: "/api/house/house/my"
    };
  },
  computed: {
    userInfo() {
      return this.detailData?.askUser?.userInfo;
    }
  }
};
</script>

<style scoped></style>
